package com.eascs.admin.o2o.loanAccount.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.account.api.ICapitalFlowService;
import com.eascs.account.api.constants.enums.LoanAccountType;
import com.eascs.app.dao.PageResult;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.util.StringUtil;
import com.eascs.common.util.UrlUtil;
import com.eascs.site.controller.BaseRestController;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.view.PaginationRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.workflow.common.vo.ModelResult;

@RestController
@RequestMapping("/rloanAccount")
public class LoanAccountRestController extends BaseRestController {
	private static Logger logger = LoggerFactory.getLogger(LoanAccountRestController.class);
	@Reference
	ICapitalFlowService capitalFlowService;

	/**
	 * @Title: buildGlfAccountPaginationInfo
	 * @Description:管理费账户明细
	 * @author 张庆奇
	 * @param accountId
	 * @param pageIndex
	 * @return
	 * @return PaginationInfo
	 * @throws @date
	 *             2017年12月13日 下午2:01:42
	 */
	@RequestMapping("/glf_account")
	public PaginationRestResult buildGlfAccountPaginationInfo(String accountId, Integer pageIndex) {
		if (pageIndex == null) {
			pageIndex = 0;
		}
		String url = "/rloanAccount/glf_account";
		url = UrlUtil.appendUrl(url, "accountId", accountId);
		url = url + "&pageIndex=";
		PageResult<Object[]> pageResult = new PageResult<Object[]>();
		if (StringUtil.isNotBlank(accountId)) {
			ModelResult<PageResult<Object[]>> glfResult = capitalFlowService.loanAccountPage(accountId,
					LoanAccountType.ISTRATION, pageIndex);
			if (glfResult.isSuccess() && glfResult.getModel() != null) {
				pageResult = glfResult.getModel();

			}

			logger.info("accountId:[{}]", accountId);
			logger.info("pageIndex:[{}]", pageIndex);
			logger.info("调用查询分页接口返回消息:[{}]", glfResult.getErrMsg());
		}
		String[] titles = { "时间", "交易流水", "交易类型", "交易方向", "交易金额（元）", "当前余额（元）", "变更前金额（元）", "摘要" };
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, url);
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setBuildRowNumber(true);
		paginationInfo.setFirstRenderColumnIndex(0);
		paginationInfo.setRendTo("#glf_account_result");
		return PaginationRestResult.buildPaginationRestResult(paginationInfo);
	}

	/**
	 * @Title: buildFxbcjAccountPaginationInfo
	 * @Description: 风险补偿金账户流水明细
	 * @author 张庆奇
	 * @param accountId
	 * @param pageIndex
	 * @return
	 * @return PaginationInfo
	 * @throws @date
	 *             2017年12月13日 下午2:00:46
	 */

	@RequestMapping("/fxbcj_account")
	public PaginationRestResult buildFxbcjAccountPaginationInfo(String accountId, Integer pageIndex) {
		String url = "/rloanAccount/fxbcj_account";
		url = UrlUtil.appendUrl(url, "accountId", accountId);
		url = url + "&pageIndex=";
		if (pageIndex == null) {
			pageIndex = 0;
		}
		PageResult<Object[]> pageResult = new PageResult<Object[]>();
		if (StringUtil.isNotBlank(accountId)) {
			ModelResult<PageResult<Object[]>> fxbcjResult = capitalFlowService.loanAccountPage(accountId,
					LoanAccountType.COMPENSATION, pageIndex);
			if (fxbcjResult.isSuccess() && fxbcjResult.getModel() != null) {
				pageResult = fxbcjResult.getModel();

			}
			logger.info("accountId:[{}]", accountId);
			logger.info("pageIndex:[{}]", pageIndex);
			logger.info("调用查询分页接口返回消息:[{}]", fxbcjResult.getErrMsg());
		}
		String[] titles = { "时间", "交易流水", "交易类型", "交易方向", "交易金额（元）", "当前余额（元）", "变更前金额（元）", "摘要" };
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, url);
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setBuildRowNumber(true);
		paginationInfo.setFirstRenderColumnIndex(0);
		paginationInfo.setRendTo("#fxbcj_account_result");
		ViewContext.put("paginationInfo", paginationInfo);
		return PaginationRestResult.buildPaginationRestResult(paginationInfo);
	}
	
	
	/**
	 * @Title: buildBzjAccountPaginationInfo
	 * @Description: 保证金账户流水明细
	 * @author 张庆奇
	 * @param accountId
	 * @param pageIndex
	 * @return
	 * @return PaginationRestResult
	 * @throws
	 * @date 2017年12月18日 上午9:54:48
	 */
	@RequestMapping("/bzj_account")
	public PaginationRestResult buildBzjAccountPaginationInfo(String accountId, Integer pageIndex) {
		String url = "/rloanAccount/bzj_account";
		url = UrlUtil.appendUrl(url, "accountId", accountId);
		url = url + "&pageIndex=";
		if (pageIndex == null) {
			pageIndex = 0;
		}
		PageResult<Object[]> pageResult = new PageResult<Object[]>();
		if (StringUtil.isNotBlank(accountId)) {
			ModelResult<PageResult<Object[]>> bzjResult = capitalFlowService.loanAccountPage(accountId,
					LoanAccountType.DEPOSIT, pageIndex);
			if (bzjResult.isSuccess() && bzjResult.getModel() != null) {
				pageResult = bzjResult.getModel();

			}
			logger.info("accountId:[{}]", accountId);
			logger.info("pageIndex:[{}]", pageIndex);
			logger.info("调用查询分页接口返回消息:[{}]", bzjResult.getErrMsg());
		}
		String[] titles = { "时间", "交易流水", "交易类型", "交易方向", "交易金额（元）", "当前余额（元）", "变更前金额（元）", "摘要" };
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, url);
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setBuildRowNumber(true);
		paginationInfo.setFirstRenderColumnIndex(0);
		paginationInfo.setRendTo("#bzj_account_result");
		ViewContext.put("paginationInfo", paginationInfo);
		return PaginationRestResult.buildPaginationRestResult(paginationInfo);
	}

}
